<?php
    include '../../../../controlador/php/conexion/Conexion.php';
    $con = new Conexion();
    
    $oidpl = $_REQUEST['oidpl'];
    $nombre = utf8_decode($_REQUEST['nombre']);
    $especi = $_REQUEST['especi'];
    $tipA = $_REQUEST['tipA'];
    $tipA2 = $_REQUEST['tipA2'];
    $tipA3 = $_REQUEST['tipA3'];
    $txtA = utf8_decode($_REQUEST['txtA']);
    $tipAb = $_REQUEST['tipAb'];
    $tipAb2 = $_REQUEST['tipAb2'];
    $txtAb = utf8_decode($_REQUEST['txtAb']);
    $tipE = utf8_decode($_REQUEST['tipE']);
    $tipE2 = $_REQUEST['tipE2'];
    $txtE = utf8_decode($_REQUEST['txtE']);
    $tipEb = $_REQUEST['tipEb'];
    $tipEb2 = $_REQUEST['tipEb2'];
    $txtEb = utf8_decode($_REQUEST['txtEb']);
    $ruta = utf8_decode($_REQUEST['ruta']);
    $rutaA = utf8_decode($_REQUEST['rutaA']);
    $lista = $_POST['lista'];
    $listaC = $_POST['listaC'];
    $listaD = $_POST['listaD'];
    $listaE = $_POST['listaE'];
    $tipEb3 = $_REQUEST['tipEb3'];
  
    
    $editar = "update ciplantilla
               set  plnombre = '".$nombre."',
                    plespecia = '".$especi."',
                    pltipoaa = '".$tipA."',
                    pltipoaab = '".$tipA2."',
                    pltipoaac ='".$tipA3."',
                    plprecargaa ='".$txtA."',
                    pltipoaba ='".$tipAb."',
                    pltipoabb ='".$tipAb2."',
                    plprecargab ='".$txtAb."',
                    pltipoea ='".$tipE."',
                    pltipoeab ='".$tipE2."',
                    plprecargea ='".$txtE."',
                    pltipoeba = '".$tipEb."',
                    pltipoebb ='".$tipEb2."',
                    pltipoebc ='".$tipEb3."',
                    plprecargeb ='".$txtEb."',
                    plrutaimgab ='".$ruta."',
                    plrutaimga ='".$rutaA."'
              where oid = '".$oidpl."'";
    $con->query($editar);
    
    $n = count($lista);
    $i = 0;
    $m = count($listaC);
    $j= 0;
    $s = count($listaD);
    $l = 0;
    $a = count($listaE);
    $f = 0;
    
    $delete = "delete from cidiagnos
               where ciplantilla = '".$oidpl."'";
    $con->query($delete);
    
    while ($i < $n){
        $insert2 = "insert into cidiagnos (ciplantilla,cidiagnoes)values('".$oidpl."','".$lista[$i]."')";
        $con->query($insert2);
       $i++;
    }
    $deleteC = "delete from ciriesgos
                where ciplantilla = '".$oidpl."'";
    $con->query($deleteC);
    
    while ($j < $m){
        $insert3 = "insert into ciriesgos(ciplantilla,ciriesgocx)values('".$oidpl."','".$listaC[$j]."')";
        $con->query($insert3);
        $j++;
    }
    $deleteD = "delete from ciriespeci
                where ciplantilla = '".$oidpl."'";
    $con->query($deleteD);
    
    while ($l < $s){
        $insert4 = "insert into ciriespeci(ciplantilla,ciriesgoe)values('".$oidpl."','".$listaD[$l]."')";
        $con->query($insert4);
        $l++;
    }
    
     $deleteE = "delete from cigrupr
                where ciplantilla = '".$oidpl."'";
    $con->query($deleteE);
    
    while ($f < $a){
        $insert5 = "insert into cigrupr(ciplantilla,cigrupries)values('".$oidpl."','".$listaE[$f]."')";
        $con->query($insert5);
        $f++;
    }
    
    
    $con->cerrarConexion();
    
?>